package com.atstudy.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/1/4 9:29
 * @copyright: 博为峰
 */
public class HashMapDemo02 {
    public static void main(String[] args) {
        HashMap<Student, String> hashMap = new HashMap<Student, String>();
        hashMap.put(new Student("张三", 20), "29期");
        hashMap.put(new Student("李四", 30), "30期");
        hashMap.put(new Student("王五", 50), "31期");
//        m1(hashMap);
        Set<Map.Entry<Student, String>> set = hashMap.entrySet();
        Iterator<Map.Entry<Student, String>> iterator = set.iterator();
        while (iterator.hasNext()){
            Map.Entry<Student, String> entry = iterator.next();

            Student key = entry.getKey();
            String value = entry.getValue();

            System.out.println(key + "," + value);
        }
    }

    private static void m1(HashMap<Student, String> hashMap) {
        Set<Student> students = hashMap.keySet();
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()) {
            Student key = iterator.next();
            String value = hashMap.get(key);
            System.out.println(key + "," + value);
        }
    }
}
